真的覺得每個能準時交功課的大大~到底是囤多少稿
當數字要顯示整數或有小數點的樣子
int x =(int)20.9
這裡會寫到字符串~
從Arrays來寫-陣列:例如聲明5個人的年齡
有兩種寫法都是可以的~
int[] userAge = { 21,22,23,24,25};
和
int[] userAge2;
userAge2 = new[] { 21, 22, 23, 24, 25 };
再來就是默認是{0,0,0,0,0}的寫法
把第一個數字0換成31的寫法:userAge3[0] = 31;
把第一個數字0換成20的寫法:userAge3[2] = userAge3[2] +20 ;
知道裡面有多少個的語法:
using System;
namespace HelloWorld2
{
class Program
{
public static void Main(string[] args)
{
int[] userAge = {21,22,23,24,25};
Console.WriteLine(userAge.Length);
}
}
}
由小排到大
using System;
namespace HelloWorld2
{
class Program
{
public static void Main(string[] args)
{
int[] userAge = {21,22,23,24,25};
Array.Sort(userAge);
}
}
}
要找21是否在裡面
using System;
namespace HelloWorld2
{
class Program
{
public static void Main(string[] args)
{
int[] numbers = {10,30,44,21,51,21,61,24,14};
int ans = Array.IndexOf(numbers,21);
}
}
}
找到21是第3個
String 字符串.一定要放在""
using System;
namespace HelloWorld2
{
class Program
{
public static void Main(string[] args)
{
string message = "Hello World" + " my name is John";
string message2 = "Hello World, my name is John";
}
}
}
裡面有幾個字:
using System;
namespace HelloWorld2
{
class Program
{
public static void Main(string[] args)
{
string message = "Hello World, ";
int ans = message.Length;
}
}
}
從第幾個開始取後面的字:
using System;
namespace HelloWorld2
{
class Program
{
public static void Main(string[] args)
{
string message = "Hello World, ";
Console.WriteLine(message.Substring(2));
}
}
}
查驗兩個字一樣嗎 equals
firstString.Equals("This is John "); //結果是true
firstString.Equals(secondString);//結果是false
using System;
namespace HelloWorld2
{
class Program
{
public static void Main(string[] args)
{
string firstString = "This is John ";
string secondString = "Hello";
firstString.Equals("This is John ");
firstString.Equals(secondString);
}
}
}
split分開~
using System;
namespace HelloWorld2
{
class Program
{
public static void Main(string[] args)
{
char[] separator = { ',', ';' };
string fruits = "Apple,Banana;Durian,,Mango";
string[] substrings=fruits.Split(separator);
Console.WriteLine(substrings);
}
}
}
DEAR ALL 我們明天見